package Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.young.peopleaccommodationms.R;
import com.example.young.peopleaccommodationms.ShowInfo;

import java.util.List;
import java.util.Map;

import DB.ShowInfoItem;

/**
 * Created by young on 2016/4/28.
 * test new os
 */
public class ShowInfoAdapter extends BaseAdapter {

    private LayoutInflater mInflater = null;
    public List<Map<String, Object>> data;

   public ShowInfoAdapter(Context context,List<Map<String, Object>> data) {
       this.mInflater = LayoutInflater.from(context);
       this.data = data;
   }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public ShowInfoItem getItem(int position) {
        return new ShowInfoItem((String)data.get(position).get("name"), (String)data.get(position).get("id"));
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.list_item_showinfo, null);
            holder.roomid_img = (ImageView) convertView.findViewById(R.id.list_item_img_roomid);
            holder.name_customer = (TextView) convertView.findViewById(R.id.list_item_name_customer);
            holder.id_curtomer = (TextView) convertView.findViewById(R.id.list_item_id_customer);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }

        //应该是一个订单集合ArrayList<OrdersBean>，多个订单一次显示，暂时以一个订单为例
//        OrdersBean orders = FileStoreRegInfo.querySingleInfo();
//        holder.roomid_img.setImageResource(R.drawable.LACUNCHER);
        holder.roomid_img.setBackgroundResource((Integer)data.get(position).get("img"));
        holder.name_customer.setText((String)data.get(position).get("name"));
        holder.id_curtomer.setText((String)data.get(position).get("id"));

        return convertView;
    }

    static  class ViewHolder{
        public ImageView roomid_img;
        public TextView name_customer;
        public TextView id_curtomer;
    }
}
